package com.yunhe.inspect.controller;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.inspect.domain.ItemPlan;
import com.yunhe.inspect.model.ItemPlanCondition;
import com.yunhe.inspect.model.ItemPlanBO;
import com.yunhe.inspect.service.ItemPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: ItemPlanController
 * @Description:
 * @author: GongDaCheng
 * @Date: 9:57 2021/11/9
 */
@Api(value = "ItemPlan", description = "项目计划维护", tags = {"Model_项目计划维护"})
@RestController
@RequestMapping(value = "/itemPlan")
public class ItemPlanController {

    @Autowired
    private ItemPlanService itemPlanService;

    /**
     * 新增
     * @author
     * @date 2021/11/09
     **/
    @ApiOperation("新增项目计划")
    @PostMapping("/createItemPlan")
    public ResponseEntity<ResultObject> createItemPlan(@RequestBody ItemPlanBO itemPlanBO) throws ArgumentErrorException {
        int count = itemPlanService.createItemPlan(itemPlanBO);
        return new ResponseEntity<>(new ResultObject<>(count), HttpStatus.OK);
    }

    /**
     * 刪除
     * @author
     * @date 2021/11/09
     **/
    @ApiOperation("根据ids删除项目计划")
    @DeleteMapping("/deleteItemPlan")
    public ResponseEntity<ResultObject> deleteItemPlan(@RequestParam(value = "ids",required = true) String ids){
        int count = itemPlanService.deleteItemPlan(ids);
        return new ResponseEntity<>(new ResultObject<>(count), HttpStatus.OK);
    }

    /**
     * 更新
     * @author
     * @date 2021/11/09
     **/
    @ApiOperation("更新项目计划")
    @PostMapping("/updateItemPlan")
    public ResponseEntity<ResultObject> updateItemPlan(@RequestBody ItemPlan itemPlan) throws ArgumentErrorException {
        int count = itemPlanService.updateItemPlan(itemPlan);
        return new ResponseEntity<>(new ResultObject<>(count), HttpStatus.OK);
    }

    /**
     * 查询 筛选项目计划
     * @author
     * @date 2021/11/09
     **/
    @ApiOperation("筛选项目计划")
    @PostMapping("/getItemPlanByCondition")
    public ResponseEntity<ResultObject<ItemPlan>> getItemPlanByCondition(@RequestBody ItemPlanCondition itemPlanCondition) throws ArgumentErrorException {
        PageResult items = itemPlanService.getItemPlanByCondition(itemPlanCondition);
        return new ResponseEntity<>(new ResultObject(items),HttpStatus.OK);
    }

    /**
     * 根据组织查询项目计划
     * @author
     * @date 2021/11/10
     **/
    @ApiOperation("根据组织查询项目计划")
    @GetMapping("/getItemPlanByOrgId")
    public ResponseEntity<ResultObject<ItemPlan>> getItemPlanByOrgId(@RequestParam(value = "orgId", required = true) Long orgId){
        List<ItemPlan> itemPlanByOrgId = itemPlanService.getItemPlanByOrgId(orgId);
        return new ResponseEntity<>(new ResultObject(itemPlanByOrgId),HttpStatus.OK);
    }
}
